package enumannoatation;

import org.junit.Test;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;

/**
 * @author lwmzzz
 * @version 1.0
 * @date 2021/3/28 20:32
 * @description 枚举和注解类test only 八种基本数据类型 String Annotation
 */
public class EnumAndAnnotationTest {

    @Retention(RetentionPolicy.RUNTIME)
    @Target({TYPE, METHOD, PARAMETER, FIELD})
    @interface MyAnnotations {
        MyAnnotation[] value();
    }

    @Repeatable(MyAnnotations.class)
    @Retention(RetentionPolicy.RUNTIME)
    @Target({TYPE, METHOD, PARAMETER, FIELD})
    @interface MyAnnotation {
        String value() default "lwm";

        int key() default 1;
    }

    class Number {
        public Integer a;
        @MyAnnotation("wqe")
        @MyAnnotation("wqe")
        @MyAnnotation("wqe")
        public String value;
    }

    enum Season {
        SPRING("春天", "1"),
        SUMMER("夏天", "2"),
        AUTUMN("秋天", "3"),
        WINTER("冬天", "4");

        private final String seasonName;
        private final String seasonDesc;

        Season(String seasonName, String seasonDesc) {
            this.seasonName = seasonName;
            this.seasonDesc = seasonDesc;
        }

        public String getSeasonName() {
            return seasonName;
        }

        public String getSeasonDesc() {
            return seasonDesc;
        }

        @Override
        public String toString() {
            return "Season{" +
                    "seasonName='" + seasonName + '\'' +
                    ", seasonDesc='" + seasonDesc + '\'' +
                    '}';
        }

        public static Season of(String description) {
            for (Season season : Season.values()) {
                if (season.getSeasonName().equals(description)) {
                    return season;
                }
            }
            return null;
        }
    }

    @Test
    public void test() {
        Season season = Season.valueOf("SPRING");
        System.out.println(Season.of("春天"));
        System.out.println(Season.of("春df天"));
        System.out.println(season);
    }
}
